import { Middleware } from 'mirai-js'
import appConfig from '../config/app.config'
import { Typeing } from '../utils/index'
class textCommandFilter extends Middleware {
  constructor(Command: string) {
    super()
    this.textProcessor().use(async (data, next) => {
      if (data && data.text) {
        if (Typeing(data.text) === 'string' && data.text.indexOf(appConfig.PREFIX) === 0) {
          const commandflx = data.text.split(appConfig.PREFIX)[1]
          if (!commandflx) return
          const content = data.text.split(' ')[1]
          const command = commandflx.split(' ')[0]
          if (command === Command) {
            data.text = content
            next()
          }
        }
      }
    })
  }
}
export { textCommandFilter }
